package com.gary.classLoad;

import java.lang.reflect.Method;
import java.util.concurrent.TimeUnit;

/**
 * @author peng_rui
 * @date 2022/4/4
 */
public class MyClassLoaderTest {
    public static void main(String[] args) throws ClassNotFoundException {
        while (true) {
            try {
                MyClassLoader myClassLoader = new MyClassLoader("D:\\codeSpace\\IDEAWorkSpace\\cloud2020\\jvm-study\\src\\main\\java\\com\\gary\\classLoad\\");
                Class<?> clazz = myClassLoader.loadClass("Demo");
                Object demo = clazz.newInstance();
                //            System.out.println(demo.getClassLoader());
    //            System.out.println(demo.getClassLoader().getParent());
                Method hello = clazz.getMethod("hello");
                hello.invoke(demo);
                TimeUnit.SECONDS.sleep(3);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
